package leetcode;

import util.TreeNode;

/**
 * @Project : AlgorithmLearning
 * @Package : Leetcode
 * @File : Q0230.java
 * @Author : WangRuoyu
 * @Date 2023/11/28 14:19
 */

public class Q0230 {
    int res = -1;
    int x = 0;
    int k;

    private void inOrder(TreeNode node) {
        if (node == null || x == k) return;
        inOrder(node.left);
        x++;
        if (x == k) {
            res = node.val;
            return;
        }
        inOrder(node.right);
    }

    public int kthSmallest(TreeNode root, int k) {
        this.k = k;
        inOrder(root);
        return res;
    }

    public static void main(String[] args) {
        Q0230 sl = new Q0230();
    }
}